<!DOCTYPE html>
<html>
<head>
	<title>我的</title>
	<meta name="keywords" content="我的"/>
	<meta name="description" content="我的">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <script type="text/javascript" src="__TMPL__/public/assets/js/jquery.min.js"></script>
	<link rel="stylesheet" type="text/css" href="__TMPL__/public/user/css/edit.css"/>
	<link rel="stylesheet" type="text/css" href="__TMPL__/public/assets/css/mobileSelect.css"/>
    <script src="__TMPL__/public/assets/js/mobileSelect.min.js"></script>
    <script type="text/javascript" src="__TMPL__/public/assets/js/layer/layer.js"></script>
    <script type="text/javascript" src="__TMPL__/public/assets/js/selectDate.js"></script>
    <script type="text/javascript" src="__TMPL__/public/assets/js/lrz.all.bundle.js"></script>

</head>
<body>

<div class="container tc-main">
	<header>
		<div class="content">
			  <a href="javascript:history.back(-1);"></a>
			<a>个人设置</a>
			<a href="{:url('user/profile/edit')}"></a>
		</div>
	</header>
	<div class="user-info-box">
		<dl class="upload-image" style="cursor: pointer;" >
			<dt class="user-logo"><h3>头像</h3>
				<h5>
					<if condition="empty($avatar)">
						<img src="__TMPL__/public/user/img/tx1.png" class="avatar"/>
						<else/>
						<img src="{:cmf_get_user_avatar_url($avatar)}" class="avatar" />
					</if>
					<i class="iconfont" style="position: relative;top: -12px;"></i>
				</h5>
				<input type="file" accept="image/*" name="logo" id="upload_pic" style="position: absolute;right: 0;opacity: 0;height: 40px;width: 71px;">
			</dt>
		</dl>
		<dl>
			<dt>
				<h3>手机</h3>
				<h5>{$mobile}</h5>
			</dt>
		</dl>
		<dl class="nickname_dl">
			<dt>
				<h3>昵称</h3>
				<h5 id="nickname">
					<span id="u_nickname">
                       {$user_nickname}
                    </span>
					<i class="iconfont"></i>
				</h5>
			</dt>
		</dl>
		<dl class="sex_dl">
			<dt>
				<h3>性别</h3>
				<h5>
                    <span id="sex">
                        <eq name="sex" value="0">保密</eq>
                        <eq name="sex" value="1">男</eq>
                        <eq name="sex" value="2">女</eq>
                    </span>
                    <i class="iconfont"></i>
                </h5>
			</dt>
		</dl>
		<dl class="birthday_dl" id="showbirth">
			<dt>
				<h3>出生日期</h3>
				<h5>
					<span id="birthday">
                          {:date('Y年 m月 d日',$birthday)}
                    </span>
					<i class="iconfont"></i>
				</h5>
			</dt>
		</dl>

     	<php>
          if(!cmf_is_wechat()){
      </php>
		<div class="uset-center-content" style=" margin-top: 51px;">
			<a href="javascript:;" onclick="location.href='{:cmf_url(\'user/Index/logout\')}'" style="text-decoration: none;">
				<dl style="width:100%;text-align:center;background:red;">
					<dt style="width:100%;text-align:center;color: #fff;margin:0;font-size: 16px;">退出登录</dt>
				</dl>
			</a>
		</div>
      <php>}</php>
	</div>

</div>
<style>
	.layui-layer-btn a{font-size: 12px}
</style>
<script type="text/javascript">
    var sex='{$sex}';
    var mobileSelect1 = new MobileSelect({
        trigger: '#sex',
        title: '性别',
        wheels: [
            {data:['保密','男','女']}
        ],
        position:[sex],
        callback:function(indexArr, data){
            console.log(indexArr); //返回选中的json数据
            $.ajax({
                type: "POST",
                url: "{:url('user/profile/edit_moblide_info')}",
                data: {
                    "sex":indexArr,
                    "type":1
				},
                dataType: "json",
                success: function (data) {
                    if(data.code==1){
                        layer.msg(data.msg);
                    }
                }
            })
        }
    });
    $.selectDate("#birthday",{
        start:1949,
        end:2028,
        select:[2012,12,21],
        title:'出生日期'
    },function (data) {
        var year=data.year;
        var month=data.month;
        var day=data.day;
        $.ajax({
            type: "POST",
            url: "{:url('user/profile/edit_moblide_info')}",
            data: {
                "year":year,
                "month":month,
                "day":day,
				"type":2
            },
            dataType: "json",
            success: function (data) {
                if(data.code==1){
                    layer.msg(data.msg);
                }
            }
        })
    });
  $(function () {
		var nick_name='{$user_nickname}';
	  $('#nickname').click(function () {
          layer.open({
              id:1,
              type: 1,
              title:'编辑昵称',
              area:['80%', 'auto'],
              content: ' <div class="row" style="width: 100%;">'
              +'<div>'
              +'<div>'
              +'<input type="text" class="nick_name" placeholder="请输入昵称" value="'+nick_name+'" style="width: 90%;margin-left: 4%;padding-left:1%;border: 1px #eee solid;height: 35px;margin-top: 3%;">'
              +'</div>'
              +'</div>'
              +'</div>'              ,
              btn:['保存'],
              btn1: function (index,layero) {
				var nick_name=$('.nick_name').val();
                  $.ajax({
                      type: "POST",
                      url: "{:url('user/profile/edit_moblide_info')}",
                      data: {
                          "nick_name":nick_name,
                          "type":3
                      },
                      dataType: "json",
                      success: function (data) {
                          layer.closeAll()
                          if(data.code==1){
                              $('#u_nickname').text(nick_name)
                              layer.msg(data.msg);
                          }
                      }
                  })
              }


          });
      })
      $("#upload_pic").change(function () {
          /* 压缩图片 */
          lrz(this.files[0], {
              width: 72, //设置压缩参数
              height:72
          }).then(function (rst) {
              /* 处理成功后执行 */
              rst.formData.append('base64img', rst.base64); // 添加额外参数
              $.ajax({
                  url: "{:url('Profile/avatarUpload')}",
                  type: "POST",
                  data: rst.formData,
                  processData: false,
                  contentType: false,
                  success: function (data) {
                      var data=eval('(' + data + ')')
                      console.log(data)
                      if (data.code == 1) {
                          var src  = "__ROOT__/upload/" + data.data.file;
                          $(".avatar").attr("src", src);
                          $.ajax({
                              type: "POST",
                              url: "{:url('user/profile/edit_moblide_info')}",
                              data: {
                                  "avatar":data.data.file,
                                  "type":4
                              },
                              dataType: "json",
                              success: function (data) {
                                  layer.closeAll()
                                  if(data.code==1){
                                      layer.msg(data.msg);
                                  }
                              }
                          })
                      }
                  }
              });
          }).catch(function (err) {
              /* 处理失败后执行 */
          }).always(function () {
              /* 必然执行 */
          })
      })
  })

</script>
</body>
</html>